看用的是什麼 browser
function () {
var ua = navigator.userAgent, tem,
M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE ' + (tem[1] || '');
}
if (M[1] === 'Chrome') {
tem = ua.match(/\b(OPR|Edge?)\/(\d+)/);
if (tem != null) return tem.slice(1).join(' ').replace('OPR', 'Opera').replace('Edg ', 'Edge ');
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((tem = ua.match(/version\/(\d+)/i)) != null) M.splice(1, 1, tem[1]);
return M.join(' ');
};
// this code snippet splits a string in a special notation
if (navigator.userAgent.indexOf("Chrome") !== -1){
// YES! The user is suspected to support look-behind regexps
// DO NOT USE /(?<=[A-Z])/. It will cause a syntax error in
// browsers that do not support look-behind expressions
// because all browsers parse the entire script, including
// sections of the code that are never executed.
var camelCaseExpression = new RegExp("(?<=[A-Z])");
var splitUpString = function(str) {
return (""+str).split(camelCaseExpression);
};
} else {
/*This fallback code is much less performant, but works*/
var splitUpString = function(str){
return str.replace(/[A-Z]/g,"z$1").split(/z(?=[A-Z])/g);
};
}
console.log(splitUpString("fooBare")); // ["fooB", "are"]
console.log(splitUpString("jQWhy")); // ["jQ", "W", "hy"]